#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 1010;
int f[N * 2];
int n, m;
int find(int x)
{
    return f[x] == x ? x : f[x] = find(f[x]);
}
void un(int x, int y)
{
    f[find(y)] = find(x);
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= 2 * n; i++)
    {
        f[i] = i;
    }
    for (int i = 1; i <= m; i++)
    {
        char a;
        int b, c;
        cin >> a >> b >> c;
        if (a == 'F')
        {
            un(b, c);
        }
        else
        {
            un(b, c + n);
            un(c, b + n);
        }
    }
    int ret = 0;
    for (int i = 1; i <= n; i++)
    {
        if (f[i] == i)
        {
            ret++;
        }
    }

    cout << ret << endl;
    return 0;
}